package cn.masterj.springcloud.controller;

import cn.masterj.springcloud.service.IPaymentSentielService;
import cn.masterj.springcloud.service.fallback.BlockFallbackFactory;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author masterJ
 * @create 2020-04-18 13:37
 */
@RestController
public class SentielController {
    @Autowired
    private IPaymentSentielService paymentSentielService;



    @GetMapping("/consumer/testA")
    public String testA(){
        return paymentSentielService.testA();
    }


    /**
     * @return
     */
    @SentinelResource(value = "testB", blockHandler = "blockHandler" , blockHandlerClass = {BlockFallbackFactory.class},fallback = "fallbackHandler", fallbackClass = BlockFallbackFactory.class)
    @GetMapping("/consumer/testB")
    public String testB(Long id){
        if (id != null && id < 0){
            throw new IllegalArgumentException("非法参数异常");
        }
        return "测试流控规则..." + paymentSentielService.testB(id);
    }


}
